package com.java2007.zhangyu.restaurant.controller;

import com.java2007.zhangyu.restaurant.pojo.FoodType;
import com.java2007.zhangyu.restaurant.service.FoodTypeService;
import com.java2007.zhangyu.restaurant.service.impl.FoodTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zy
 * @Version
 * @date 2021/01/23
 */
@WebServlet("/foodtype/querybyftid")
public class FoodTypeQueryByFoodTypeIdServlet extends HttpServlet {

    private FoodTypeService foodTypeService = new FoodTypeServiceImpl();

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        try {
            //获取请求参数
            String fTypeIdStr = request.getParameter("fTypeId");
            //将字符串类型转换为整型
            int fTypeId = Integer.parseInt(fTypeIdStr);
            //根据菜类别名id查询菜类别的信息
            FoodType foodType = foodTypeService.queryByFoodTypeId(fTypeId);
            //将查询到的信息放到 request域中
            request.setAttribute("type",foodType);
            //转发
            request.getRequestDispatcher("/backend/detail/foodtype/food-type-update.jsp").forward(request,response);
        } catch (Exception e) {
            e.printStackTrace();
            request.getRequestDispatcher("../../backend/index.jsp").forward(request, response);
        }
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
